import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { SFSchema, SFComponent, SFDateWidgetSchema } from '@delon/form';
import { STColumn,ReuseTabService } from '@delon/abc';
import { GridComponent,HttpService,SupDic } from 'lbf';
import {Router} from '@angular/router';
import {NzMessageService } from 'ng-zorro-antd';


@Component({
  selector: 'app-xxgl-xxfswh',
  templateUrl: './xxfswh.component.html',
})
export class XxglXxfswhComponent implements OnInit {

  param = {sname: 'XXGL_XXFSCX',queryparas: {}}

  schema:SFSchema = {
    properties: {
      start: {
        type: 'string',
        title: '发送日期',
        ui: { widget: 'date', end: 'end' },
      },
      end: {
        type: 'string',
        ui: { widget: 'date', end: 'end' },
      },
    }
  }

  columns:STColumn[] = [
    {title:'收件人',index: 'JSR',format: (record) => this.supdic.getdicLabel('USERID',record.JSR)},
    {title: '标题',type:'link',index: 'XTITLE',click: (record) => this.xxDetail(record),width:700,
     format: (record) => record.XTITLE === ' '?'(无主题)':record.XTITLE},
    {title: '时间',index: 'FSSJ'},
    {
      title: '操作区',
      buttons: [
        {
          text: '删除',
          click: (record) =>this.xxDel(record),
          pop: true,
          popTitle: '是否删除此条信息？'
        }
      ]
    }
  ]

  @ViewChild('st',{static: false}) st: GridComponent;
  @ViewChild('sf',{static: false}) sf: SFComponent;
  constructor(private http: _HttpClient,private httpService: HttpService,
    private route: Router,private msgSrv: NzMessageService,
    private reuseService: ReuseTabService,private supdic: SupDic) { }

  ngOnInit() { }

  btfz(record){
    console.log(record)
    if(record.XTITLE === ' '){
      return '(无主题)';
    }
    return record.XTITLE;
  }

  xxDetail(record){
    record['FS'] = true;
    this.route.navigate(['/xxgl/xxxq'],{queryParams: record});
  }


  xxDel(record){
    this.httpService.lbservice('XXGL_XXFSSC',{XXID: record.XXID,JSR: record.JSR}).then(res =>{
      if(res.code >0){
        this.msgSrv.success('删除成功');
        this.st.reload({}); 
      }  
      else this.msgSrv.error(res.error);
    } )
  }

  add(){
    this.route.navigateByUrl('/xxgl/xxfs');
  }

  query(){
   if(this.sf.value.hasOwnProperty('start')){
    this.sf.value.start =  this.sf.value.start.split(' ')[0];
    this.sf.value.end =  this.sf.value.end.split(' ')[0];
   }
   this.st.reload(this.sf.value);
  }

  _onReuseInit(){
    this.st.reload({})
  }
}
